package com.paradogs.gs.modules.shop;

import com.paradogs.common._cfg.Cfg;
import com.paradogs.framework.annotations.serverHandler.PRHandler;
import com.paradogs.framework.annotations.serverHandler.PRMapping;
import com.paradogs.framework.misc.GC;
import com.paradogs.gs.misc.Bow;
import com.paradogs.gs.modules.shop.msg.CGShopBuy;
import lombok.extern.slf4j.Slf4j;

/**
 * @author: yumi
 * @date: 2024/12/27  9:24
 * @Description: TODO
 */
@Slf4j
@PRHandler
@PRMapping("shop")
public class ShopHandler {

    @PRMapping("buy")
    public GC buy(CGShopBuy cg) {

        Bow.asserts(Cfg.Shop.get(cg.getCfgId()) != null," 找不到商品");
        Bow.asserts(cg.getCount() != null,"购买数量不正确");

        Cfg.Shop cfg = Cfg.Shop.get(cg.getCfgId());
        Bow.owner().inventoryMgr().update(cfg.consume(), cfg.gain());

        return GC.ok();
    }

}
